home *** CD-ROM | disk | FTP | other *** search
- //------------------------------------------------------------------------------
- // File: $$CLASS_NAME$$.cpp
- //
- // Desc: DirectMusicTool Wizard generated code - Implementation of $$CLASS_NAME$$
- //
- // Author: $$TOOL_AUTHOR$$
- //
- // Copyright (c) Microsoft Corporation. All rights reserved.
- //------------------------------------------------------------------------------
-
-
- #if _MSC_VER > 1000
- #pragma once
- #endif // _MSC_VER > 1000
-
- #define STRICT
- #ifndef _WIN32_WINNT
- #define _WIN32_WINNT 0x0400
- #endif
-
- #define _ATL_FREE_THREADED
- #define _ATL_STATIC_REGISTRY
-
- #include <atlbase.h>
- //You may derive a class from CComModule and use it if you want to override
- //something, but do not change the name of _Module
- extern CComModule _Module;
- #include <atlcom.h>
- #include <atlctl.h>
- #include <statreg.h>
- #include <statreg.cpp>
- #include <atlimpl.cpp>
-
-
- #include "$$CLASS_NAME$$.h"
-
- /////////////////////////////////////////////////////////////////////////////
- // TODO List:
- // - Implement ProcessPMsg(), Init(), Flush()
- // - Complete implementation for $$CLASS_NAME$$() and ~$$CLASS_NAME$$()
- // if necessary
- $$IF(SUPPORT_DM_IMEDPARAM || SUPPORT_DM_DMP)
- // - Complete implementation for SetAllParameters()
- // - Complete implementation for GetAllParameters()
- // - Complete implementation for SetParamInternal()
- $$ENDIF
- // - Implement your custom memeber functions
- //
- /////////////////////////////////////////////////////////////////////////////
-
- //
- // Interface Implementation
- //
-
- //-----------------------------------------------------------------------------
- // Name: $$CLASS_NAME$$::$$CLASS_NAME$$()
- // Desc: Constructor
- //-----------------------------------------------------------------------------
- $$CLASS_NAME$$::$$CLASS_NAME$$()
- {
- $$IF(SUPPORT_DM_IMEDPARAM || SUPPORT_DM_DMP)
- m_fDirty = TRUE;
- $$ENDIF
- m_fInitialized = FALSE;
-
- $$IF(SUPPORT_DM_IMEDPARAM || SUPPORT_DM_DMP)
- // Initialize parameters in IMediaParam
- InitParams(1, &GUID_TIME_REFERENCE, 0, 0, sizeof(g_params)/sizeof(*g_params), g_params);
- $$ENDIF
-
- $$IF(EMPTY_TOOL)
- // TODO: Add initialization code here
- m_dwParam1 = 0; // m_dwParam1 is provided as an example
-
- $$ELSE // Sample tool
- m_dwEchoNum = 3; // Default to 3 echoes per note
- m_mtDelay = DMUS_PPQ / 2; // Default to 8th note echoes
- $$ENDIF
- }
-
- //-----------------------------------------------------------------------------
- // Name: $$CLASS_NAME$$::~$$CLASS_NAME$$()
- // Desc: Destructor
- //-----------------------------------------------------------------------------
- $$CLASS_NAME$$::~$$CLASS_NAME$$()
- {
- // TODO: Add uninitialization code here
- //
-
- }
-
- //-----------------------------------------------------------------------------
- // Name: $$CLASS_NAME$$::Init()
- // Desc: Initialize the tool
- //
- // Param: pGraph - the Calling graph
- //
- // Return: If succeeded, the method should return S_OK. If it fails, the return
- // value might be E_POINTER or E_OUTOFMEMORY
- //
- // Remarks: This method is called when the tool is inserted into the graph,
- // giving the tool an opportunity to perform any necessary
- // initialization. Because a tool can be inserted into more than one
- // graph, this method must be able to deal gracefully with multiple
- // calls. Be sure not to create a circular reference to the graph
- // represented by pGraph.
- //
- // **This method is currently not implemeneted by the wizard**
- //
- //-----------------------------------------------------------------------------
- STDMETHODIMP $$CLASS_NAME$$::Init( IDirectMusicGraph* pGraph )
- {
- HRESULT hr = S_OK;
-
- // TODO: Do some initialization here if necessary
- //
-
- if(SUCCEEDED (hr))
- {
- m_fInitialized = TRUE;
- }
-
- return S_OK;
- }
-
- //-----------------------------------------------------------------------------
- // Name: $$CLASS_NAME$$::Clone()
- // Desc: Create a new instance of the tool
- //
- // Param: ppTool - Address of a variable that receives a pointer to the
- // IDirectMusicTool interface of the new instnace of the
- // tool. Use QueryInterface to obtain IDirectMusicTool8.
- //
- // Return: If succeeded, the method should return S_OK. If it fails, the return
- // value might be E_POINTER, E_NOINTERFACE or E_OUTOFMEMORY
- //-----------------------------------------------------------------------------
- STDMETHODIMP $$CLASS_NAME$$::Clone( IDirectMusicTool ** ppTool)
- {
- if( NULL == ppTool ) // Make sure pointer does not fail
- {
- return E_POINTER;
- }
-
- $$CLASS_NAME$$ *pNew = new CComObject<$$CLASS_NAME$$>;
- if (pNew)
- {
- HRESULT hr = pNew->QueryInterface( IID_IDirectMusicTool, (void **) ppTool );
- if(SUCCEEDED(hr) && ppTool)
- {
- $$IF(SUPPORT_DM_IMEDPARAM || SUPPORT_DM_DMP)
- $$TOOLID_NAME$$Params params;
- hr = this->GetAllParameters(¶ms);
-
- if(SUCCEEDED(hr))
- {
- hr = pNew->SetAllParameters(¶ms);
- }
-
- return hr;
- $$ELSE
- return S_OK;
- $$ENDIF
- }
- else
- {
- return E_NOINTERFACE;
- }
- }
- else
- {
- return E_OUTOFMEMORY;
- }
- }
-
- //-----------------------------------------------------------------------------
- // Name: $$CLASS_NAME$$::GetMsgDeliveryType()
- // Desc: Retrieve the tool's delivery type, which determines when messages are
- // to be delivered to the tool
- //
- // Param: pdwDeliveryType - Address of a variable that receives the delivery type
- //
- // Return: If succeeded, the method should return S_OK. If it fails, the
- // method can return E_POINTER
- //-----------------------------------------------------------------------------
- STDMETHODIMP $$CLASS_NAME$$::GetMsgDeliveryType( DWORD* pdwDeliveryType )
- {
- if( NULL == pdwDeliveryType ) // Make sure pointer does not fail
- {
- return E_POINTER;
- }
-
- $$IF(DELIVERYTYPE_IMMEDIATE)
- *pdwDeliveryType = DMUS_PMSGF_TOOL_IMMEDIATE;
- $$ELIF(DELIVERYTYPE_QUEUE)
- *pdwDeliveryType = DMUS_PMSGF_TOOL_QUEUE;
- $$ELIF(DELIVERYTYPE_ATTIME)
- *pdwDeliveryType = DMUS_PMSGF_TOOL_ATTIME;
- $$ELIF(!DELIVERYTYPE_IMMEDIATE && !DMUS_PMSGF_TOOL_QUEUE && !DMUS_PMSGF_TOOL_ATTIME)
- // Set to default "DMUS_PMSGF_TOOL_IMMEDIATE"
- *pdwDeliveryType = DMUS_PMSGF_TOOL_IMMEDIATE;
- $$ENDIF
-
- return S_OK;
- }
-
- //-----------------------------------------------------------------------------
- // Name: $$CLASS_NAME$$::GetMediaTypeArraySize()
- // Desc: Retrieve the size of the array that must be passed into the
- // IDirectMusicTool8::GetMediaTypes method
- //
- // Param: pdwNumElements - Address of a variable that receives the number of
- // media types
- //
- // Return: If succeeded, the method should return S_OK. If it fails, the
- // method can return E_POINTER
- //-----------------------------------------------------------------------------
- STDMETHODIMP $$CLASS_NAME$$::GetMediaTypeArraySize( DWORD* pdwNumElements )
- {
- if( NULL == pdwNumElements ) // Make sure pointer does not fail
- {
- return E_POINTER;
- }
-
- *pdwNumElements = $$TYPECOUNT$$;
-
- return S_OK;
- }
-
- //-----------------------------------------------------------------------------
- // Name: $$CLASS_NAME$$::GetMediaTypes()
- // Desc: Get an array of the types processed by this tool
- //
- // Param: padwMediaTypes - Address of an array of DWORDs. The method fills
- // this array with the media types supported by this tool
- // dwNumElements - Number of elements in the padwMediaTypes array.
- // This value is equal to the number returned by the
- // IDirectMusicTool8::GetMediaTypeArraySize method
- //
- // Return: If succeeded, the method should return S_OK. If it fails, the return
- // value might be E_POINTER or E_OUTOFMEMORY
- //-----------------------------------------------------------------------------
- STDMETHODIMP $$CLASS_NAME$$::GetMediaTypes( DWORD** padwMediaTypes,
- DWORD dwNumElements )
- {
- if( NULL == padwMediaTypes ) // Make sure pointer does not fail
- {
- return E_POINTER;
- }
-
- // Fill in the array padwMediaTypes with the type of
- // messages this tool wants to process if dwNumElements is equal to
- // the returns from GetMediaTypeArraySize().
-
- if( dwNumElements == $$TYPECOUNT$$ )
- {
- $$IF(TYPECOUNT_0)
- (*padwMediaTypes)[0] = $$TYPE_0$$;
- $$ENDIF // TYPECOUNT_0
- $$IF(TYPECOUNT_1)
- (*padwMediaTypes)[1] = $$TYPE_1$$;
- $$ENDIF // TYPECOUNT_1
- $$IF(TYPECOUNT_2)
- (*padwMediaTypes)[2] = $$TYPE_2$$;
- $$ENDIF // TYPECOUNT_2
- $$IF(TYPECOUNT_3)
- (*padwMediaTypes)[3] = $$TYPE_3$$;
- $$ENDIF // TYPECOUNT_3
- $$IF(TYPECOUNT_4)
- (*padwMediaTypes)[4] = $$TYPE_4$$;
- $$ENDIF // TYPECOUNT_4
- $$IF(TYPECOUNT_5)
- (*padwMediaTypes)[5] = $$TYPE_5$$;
- $$ENDIF // TYPECOUNT_5
- $$IF(TYPECOUNT_6)
- (*padwMediaTypes)[6] = $$TYPE_6$$;
- $$ENDIF // TYPECOUNT_6
- $$IF(TYPECOUNT_7)
- (*padwMediaTypes)[7] = $$TYPE_7$$;
- $$ENDIF // TYPECOUNT_7
- $$IF(TYPECOUNT_8)
- (*padwMediaTypes)[8] = $$TYPE_8$$;
- $$ENDIF // TYPECOUNT_8
- $$IF(TYPECOUNT_9)
- (*padwMediaTypes)[9] = $$TYPE_9$$;
- $$ENDIF // TYPECOUNT_9
- $$IF(TYPECOUNT_10)
- (*padwMediaTypes)[10] = $$TYPE_10$$;
- $$ENDIF // TYPECOUNT_10
- $$IF(TYPECOUNT_11)
- (*padwMediaTypes)[11] = $$TYPE_11$$;
- $$ENDIF // TYPECOUNT_11
- $$IF(TYPECOUNT_12)
- (*padwMediaTypes)[12] = $$TYPE_12$$;
- $$ENDIF // TYPECOUNT_12
- $$IF(TYPECOUNT_13)
- (*padwMediaTypes)[13] = $$TYPE_13$$;
- $$ENDIF // TYPECOUNT_13
- $$IF(TYPECOUNT_14)
- (*padwMediaTypes)[14] = $$TYPE_14$$;
- $$ENDIF // TYPECOUNT_14
- $$IF(TYPECOUNT_15)
- (*padwMediaTypes)[15] = $$TYPE_15$$;
- $$ENDIF // TYPECOUNT_15
- return S_OK;
- }
- else
- {
- // This should never happen
- return E_FAIL;
- }
- }
-
- //-----------------------------------------------------------------------------
- // Name: $$CLASS_NAME$$::ProcessPMsg()
- // Desc: Perform the main task of the tool -- process PMsg
- //
- // Param: pPerf - Performance that is generating messages
- // pPMsg - Message to process
- //
- // Return: If succeeded, the method should return one of DMUS_S_REQUEUE,
- // DMUS_S_FREE, or S_OK. If it fails, the method can return E_POINTER
- //
- //-----------------------------------------------------------------------------
- STDMETHODIMP $$CLASS_NAME$$::ProcessPMsg( IDirectMusicPerformance* pPerf,
- DMUS_PMSG* pPMsg )
- {
- if( NULL == pPerf || NULL == pPMsg ) // Make sure pointers do not fail
- {
- return E_POINTER;
- }
-
- // Save the current PChannel, since calling StampPMsg may change it.
- // TODO: Uncomment the following line if you need to remember the PChannel
- //DWORD dwPChannel = pPMsg->dwPChannel;
-
- // Stamp the message to be delivered to the next tool in the graph.
- // If StampPMsg fails, there is no destination for this message, so
- // tell the performance to free it.
- if(( NULL == pPMsg->pGraph ) ||
- FAILED(pPMsg->pGraph->StampPMsg(pPMsg)))
- {
- return DMUS_S_FREE;
- }
-
- $$IF(SUPPORT_DM_IMEDPARAM || SUPPORT_DM_DMP)
- // Update parameter values from any curves that may be in effect.
- // We pick up the current values stored in the CParamsManager helper for time rtStart.
- this->UpdateActiveParams(pPMsg->rtTime, *this);
- $$ENDIF
-
- $$IF(EMPTY_TOOL)
-
- // TODO: Add your custom code here
-
- // Process each message type
- switch(pPMsg->dwType)
- {
- $$IF(PROCESS_MIDI)
- case DMUS_PMSGT_MIDI:
- // TODO: Add your process code for PMsg type DMUS_PMSGT_MIDI
-
- break;
- $$ENDIF
- $$IF(PROCESS_NOTE)
- case DMUS_PMSGT_NOTE:
- // TODO: Add your process code for PMsg type DMUS_PMSGT_NOTE
-
- break;
- $$ENDIF
- $$IF(PROCESS_SYSEX)
- case DMUS_PMSGT_SYSEX:
- // TODO: Add your process code for PMsg type DMUS_PMSGT_SYSEX
-
- break;
- $$ENDIF
- $$IF(PROCESS_NOTIFICATION)
- case DMUS_PMSGT_NOTIFICATION:
- // TODO: Add your process code for PMsg type DMUS_PMSGT_NOTIFICATION
-
- break;
- $$ENDIF
- $$IF(PROCESS_TEMPO)
- case DMUS_PMSGT_TEMPO:
- // TODO: Add your process code for PMsg type DMUS_PMSGT_TEMPO
-
- break;
- $$ENDIF
- $$IF(PROCESS_CURVE)
- case DMUS_PMSGT_CURVE:
- // TODO: Add your process code for PMsg type DMUS_PMSGT_CURVE
-
- break;
- $$ENDIF
- $$IF(PROCESS_TIMESIG)
- case DMUS_PMSGT_TIMESIG:
- // TODO: Add your process code for PMsg type DMUS_PMSGT_TIMESIG
-
- break;
- $$ENDIF
- $$IF(PROCESS_PATCH)
- case DMUS_PMSGT_PATCH:
- // TODO: Add your process code for PMsg type DMUS_PMSGT_PATCH
-
- break;
- $$ENDIF
- $$IF(PROCESS_TRANSPOSE)
- case DMUS_PMSGT_TRANSPOSE:
- // TODO: Add your process code for PMsg type DMUS_PMSGT_TRANSPOSE
-
- break;
- $$ENDIF
- $$IF(PROCESS_CHANNEL_PRIORITY)
- case DMUS_PMSGT_CHANNEL_PRIORITY:
- // TODO: Add your process code for PMsg type DMUS_PMSGT_CHANNEL_PRIORITY
-
- break;
- $$ENDIF
- $$IF(PROCESS_STOP)
- case DMUS_PMSGT_STOP:
- // TODO: Add your process code for PMsg type DMUS_PMSGT_STOP
-
- break;
- $$ENDIF
- $$IF(PROCESS_DIRTY)
- case DMUS_PMSGT_DIRTY:
- // TODO: Add your process code for PMsg type DMUS_PMSGT_DIRTY
-
- break;
- $$ENDIF
- $$IF(PROCESS_WAVE)
- case DMUS_PMSGT_WAVE:
- // TODO: Add your process code for PMsg type DMUS_PMSGT_WAVE
-
- break;
- $$ENDIF
- $$IF(PROCESS_LYRIC)
- case DMUS_PMSGT_LYRIC:
- // TODO: Add your process code for PMsg type DMUS_PMSGT_LYRIC
-
- break;
- $$ENDIF
- $$IF(PROCESS_SCRIPTLYRIC)
- case DMUS_PMSGT_SCRIPTLYRIC:
- // TODO: Add your process code for PMsg type DMUS_PMSGT_SCRIPTLYRIC
-
- break;
- $$ENDIF
- $$IF(PROCESS_USER)
- case DMUS_PMSGT_USER:
- // TODO: Add your process code for PMsg type DMUS_PMSGT_USER
-
- break;
- $$ENDIF
- default: { /* TODO: Do something for default if necessary */ }
- }
-
- // TODO: Remeber to deallocate local variables that are no longer needed
-
-
- $$IF(POSTPROC_REQUEUE)
- return DMUS_S_REQUEUE; // Requeue message
- $$ELIF(POSTPROC_FREE)
- return DMUS_S_FREE; // Free message automatically (PMsg no longer needed)
- $$ELIF(POSTPROC_S_OK)
- return S_OK;
- $$ELIF(!DELIVERYTYPE_IMMEDIATE && !DMUS_PMSGF_TOOL_QUEUE && !DMUS_PMSGF_TOOL_ATTIME)
- // Set to default "DMUS_S_REQUEUE"
- return DMUS_S_REQUEUE; // Requeue message
- $$ENDIF
-
- $$ELSE // Sample Tool
-
- DWORD dwCount;
- DWORD dwEchoNum;
- MUSIC_TIME mtDelay;
-
- // SetEchoNum() and SetDelay() use these member variables,
- dwEchoNum = m_dwEchoNum;
- mtDelay = m_mtDelay;
-
- // The Tool is set up to only receive messages of types
- // DMUS_PMSGT_NOTE, DMUS_PMSGT_MIDI, DMUS_PMSGT_SYSEX, or DMUS_PMSGT_PATCH
- // We use the DX8 ClonePMsg method to make a copy of the pmsg and
- // send it to a pchannel in the next pchannel group.
- // If it's a note, we also doctor the velocity.
- IDirectMusicPerformance8 *pPerf8;
- if (SUCCEEDED(pPerf->QueryInterface(IID_IDirectMusicPerformance8,(void **)&pPerf8)))
- {
- for( dwCount = 1; dwCount <= dwEchoNum; dwCount++ )
- {
- DMUS_PMSG *pClone;
- if( SUCCEEDED( pPerf8->ClonePMsg( pPMsg,&pClone)))
- {
- // Add to the time of the echoed note
- pClone->mtTime += (dwCount * mtDelay);
- if (pPMsg->dwType == DMUS_PMSGT_NOTE )
- {
- DMUS_NOTE_PMSG *pNote = (DMUS_NOTE_PMSG*)pPMsg;
- DMUS_NOTE_PMSG *pCloneNote = (DMUS_NOTE_PMSG*)pClone;
- // Reduce the volume of the echoed note
- // percentage of reduction in velocity increases with each echo
- pCloneNote->bVelocity = (BYTE) (pNote->bVelocity -
- ((pNote->bVelocity * (dwCount * 15)) / 100));
- }
- // Set the note so only MUSIC_TIME is valid.
- // REFERENCE_TIME will be recomputed inside
- // SendPMsg()
- pClone->dwFlags = DMUS_PMSGF_MUSICTIME;
- pClone->dwPChannel = pPMsg->dwPChannel + (16 * dwCount);
- // Queue the echoed PMsg
- pPerf->SendPMsg(pClone);
- }
- }
- pPerf8->Release();
- }
-
- // Return DMUS_S_REQUEUE so the original message is requeued
- return DMUS_S_REQUEUE;
- $$ENDIF
- }
-
- //-----------------------------------------------------------------------------
- // Name: $$CLASS_NAME$$::Flush()
- // Desc: Flushes messages from the queue when the performance stops
- //
- // Param: pPerf - Address of the IDirectMusicPerformance8 interface
- // pDMUS_PMSG - Message to flush
- // rt - Time at which to flush
- //
- // Return: If succeeded, the method should return one of DMUS_S_REQUEUE,
- // DMUS_S_FREE, or S_OK. If it fails, the method can return E_POINTER
- //
- //
- // Remarks: The tool can use the method to do whatever is necessary to flush
- // the message. For instance, the output tool uses this method to
- // ensure that any pending note-off messages are processed immediately
- //
- // **This method is currently not implemeneted by the wizard**
- //
- //-----------------------------------------------------------------------------
- STDMETHODIMP $$CLASS_NAME$$::Flush( IDirectMusicPerformance* pPerf,
- DMUS_PMSG* pDMUS_PMSG,
- REFERENCE_TIME rt)
- {
- // TODO: To implement, replace the following line with your code
- //
- return DMUS_S_REQUEUE;
- }
-
- $$IF(!EMPTY_TOOL) // Sample Tool
- //-----------------------------------------------------------------------------
- // Name: $$CLASS_NAME$$::SetEchoNum()
- // Desc: Set the number of echoes. Upperbound set by MAX_ECHOES
- //-----------------------------------------------------------------------------
- STDMETHODIMP_(void) $$CLASS_NAME$$::SetEchoNum( DWORD dwEchoNum )
- {
- if( dwEchoNum <= MAX_ECHOES )
- {
- m_dwEchoNum = dwEchoNum;
- }
- }
-
- //-----------------------------------------------------------------------------
- // Name: $$CLASS_NAME$$::SetDelay()
- // Desc: Set the length of delay for each echo
- //-----------------------------------------------------------------------------
- STDMETHODIMP_(void) $$CLASS_NAME$$::SetDelay( MUSIC_TIME mtDelay )
- {
- m_mtDelay = mtDelay;
- }
- $$ENDIF // End => Sample tool
-
-
- $$IF(SUPPORT_DM_IMEDPARAM || SUPPORT_DM_DMP)
- //-----------------------------------------------------------------------------
- // Name: $$CLASS_NAME$$::SetParamInternal()
- // Desc: Set the indicated parameter
- //-----------------------------------------------------------------------------
- HRESULT $$CLASS_NAME$$::SetParamInternal(DWORD dwParamIndex, MP_DATA value, bool fSkipPasssingToParamManager)
- {
- switch (dwParamIndex)
- {
- $$IF(EMPTY_TOOL)
- case $$TOOL_DEFINE$$_PARAM1:
- m_dwParam1 = (DWORD)value; // m_dwParam1 is provided as an example
- break;
- // TODO: Add cases for each of your parameters
- $$ELSE // Sample DMTool
- case ECHO_NUMBER:
- m_dwEchoNum = (DWORD)value;
- break;
- case ECHO_DELAY:
- m_mtDelay = (MUSIC_TIME)value;
- break;
- $$ENDIF // End EMPTY_TOOL
- }
-
- // Let base class set this so it can handle all the rest of the param calls.
- // Skip the base class if fSkipPasssingToParamManager. This indicates that we're calling the function
- // internally using values that came from the base class -- thus there's no need to tell it values it
- // already knows.
- return fSkipPasssingToParamManager ? S_OK : CParamsManager::SetParam(dwParamIndex, value);
- }
-
- //////////////////
- // Macros used by GetAllParameters() and SetAllParameters()
- //
- // GET_PARAM_DWORD()
- #define GET_PARAM_DWORD(x, y) \
- if (SUCCEEDED(hr)) \
- { \
- hr = GetParam(x, &var); \
- if (SUCCEEDED(hr)) \
- { \
- y = (DWORD)var; \
- } \
- }
-
- // GET_PARAM_FLOAT()
- #define GET_PARAM_FLOAT(x, y) \
- if (SUCCEEDED(hr)) \
- { \
- hr = GetParam(x, &var); \
- if (SUCCEEDED(hr)) \
- { \
- y = (float)var; \
- } \
- }
-
- // SET_PARAM()
- #define SET_PARAM(x, y) \
- if (SUCCEEDED(hr)) \
- { \
- hr = SetParam(x, static_cast<MP_DATA>(y)); \
- }
-
- //-----------------------------------------------------------------------------
- // Name: $$CLASS_NAME$$::SetAllParameters()
- // Desc: Set all parameters
- //-----------------------------------------------------------------------------
- STDMETHODIMP $$CLASS_NAME$$::SetAllParameters(THIS_ LPC$$TOOLID_NAME$$Params pParm)
- {
- HRESULT hr = S_OK;
-
- // Check that the pointer is not NULL
- if (pParm == NULL)
- {
- hr = E_POINTER;
- }
-
- // Set the parameters
- if (SUCCEEDED(hr))
- {
- $$IF(EMPTY_TOOL)
- // TODO: Set all parameters with values stored in pParm. Example:
- SET_PARAM($$TOOL_DEFINE$$_PARAM1, pParm->dwParam1);
- // End of Example
- $$ELSE // Sample DMTool
- SET_PARAM(ECHO_NUMBER, pParm->dwNumber);
- SET_PARAM(ECHO_DELAY, pParm->dwDelay);
- $$ENDIF // End EMPTY_TOOL
- }
-
- m_fDirty = TRUE;
- return hr;
- }
-
- //-----------------------------------------------------------------------------
- // Name: $$CLASS_NAME$$::GetAllParameters()
- // Desc: Set all parameters
- //-----------------------------------------------------------------------------
- STDMETHODIMP $$CLASS_NAME$$::GetAllParameters(THIS_ LP$$TOOLID_NAME$$Params pParm)
- {
- HRESULT hr = S_OK;
- MP_DATA var;
-
- if (pParm == NULL)
- {
- return E_POINTER;
- }
-
- $$IF(EMPTY_TOOL)
- // TODO: Get all parameter values into pParm.
- // Example:
- GET_PARAM_DWORD($$TOOL_DEFINE$$_PARAM1, pParm->dwParam1);
- // End of Example
- $$ELSE // Sample DMTool
- GET_PARAM_DWORD(ECHO_NUMBER, pParm->dwNumber);
- GET_PARAM_DWORD(ECHO_DELAY, pParm->dwDelay);
- $$ENDIF // End EMPTY_TOOL
-
- return hr;
- }
-
- //-----------------------------------------------------------------------------
- // Name: $$CLASS_NAME$$::GetClassID()
- // Desc: Get the class ID for this class
- //-----------------------------------------------------------------------------
- HRESULT $$CLASS_NAME$$::GetClassID(CLSID *pClsid)
- {
- // Check for valid pointer
- if( NULL == pClsid )
- {
- return E_POINTER;
- }
-
- *pClsid = CLSID_$$TOOL_DEFINE$$;
- return S_OK;
-
- } // GetClassID
-
-
- //-----------------------------------------------------------------------------
- // Name: $$CLASS_NAME$$::IsDirty()
- // Desc: Checks the object for changes since it was last saved
- //-----------------------------------------------------------------------------
- HRESULT $$CLASS_NAME$$::IsDirty()
- {
- return m_fDirty ? S_OK : S_FALSE;
- }
-
- //-----------------------------------------------------------------------------
- // Name: $$CLASS_NAME$$::Load()
- // Desc: Initializes an object from the stream where it was previously saved
- //-----------------------------------------------------------------------------
- HRESULT $$CLASS_NAME$$::Load(IStream *pStm)
- {
- ULONG ulSizeRead = 0;
- HRESULT hr = S_OK;
-
- if ( pStm == NULL )
- {
- return E_POINTER;
- }
-
- $$TOOLID_NAME$$Params params;
- $$IF(SUPPORT_DM_DMP)
-
- // Since DirectMusic expects the data to be in RIFF format, we'll read
- // the input as a valid RIFF chunk
- DWORD dwChunkID;
- DWORD dwSize;
-
- // Read RIFF form type chunk
- hr = pStm->Read((void *)&dwChunkID, sizeof(dwChunkID), &ulSizeRead);
- if (FAILED(hr) || dwChunkID != FOURCC_TOOL_CHUNK) // If Read() failed or invalid chunk type
- {
- return hr;
- }
-
- // Read RIFF size chunk
- hr = pStm->Read((void *)&dwSize, sizeof(dwSize), &ulSizeRead);
- if (FAILED(hr) || dwSize != sizeof($$TOOLID_NAME$$Params)) // If Read() failed or invalid chunk size
- {
- return hr;
- }
- $$ENDIF // End SUPPORT_DM_DMP
-
- // Read the parameters
- hr = pStm->Read((void *)¶ms, sizeof(params), &ulSizeRead);
- if (hr != S_OK || ulSizeRead < sizeof(params))
- {
- return E_FAIL;
- }
-
- hr = SetAllParameters(¶ms);
-
- m_fDirty = FALSE;
-
- return hr;
- }
-
- //-----------------------------------------------------------------------------
- // Name: $$CLASS_NAME$$::Save()
- // Desc: This method saves an object to the specified stream
- //-----------------------------------------------------------------------------
- HRESULT $$CLASS_NAME$$::Save(IStream *pStm, BOOL fClearDirty)
- {
- HRESULT hr = S_OK;
-
- if ( pStm == NULL )
- {
- return E_POINTER;
- }
-
- $$TOOLID_NAME$$Params params;
- hr = GetAllParameters(¶ms);
- if (FAILED(hr))
- {
- return hr;
- }
-
- ULONG ulSizeWritten = 0;
- $$IF(SUPPORT_DM_DMP)
-
- // Since DirectMusic expects the data to be in RIFF format, we'll make
- // the output to pStm a valid RIFF chunk
- DWORD dwChunkID = FOURCC_TOOL_CHUNK;
- DWORD dwSize = sizeof($$TOOLID_NAME$$Params);
-
- // Write RIFF form type chunk
- hr = pStm->Write((void *)&dwChunkID, sizeof(dwChunkID), &ulSizeWritten);
- if (FAILED(hr))
- {
- return hr;
- }
-
- // Write RIFF size chunk
- hr = pStm->Write((void *)&dwSize, sizeof(dwSize), &ulSizeWritten);
- if (FAILED(hr))
- {
- return hr;
- }
- $$ENDIF // End SUPPORT_DM_DMP
-
- // Write the parameters
- hr = pStm->Write((void *)¶ms, sizeof(params), &ulSizeWritten);
-
- if (hr != S_OK || ulSizeWritten < sizeof(params))
- {
- return E_FAIL;
- }
-
- if (fClearDirty)
- {
- m_fDirty = FALSE;
- }
-
- return S_OK;
- }
-
- //-----------------------------------------------------------------------------
- // Name: $$CLASS_NAME$$::GetSizeMax()
- // Desc: This method returns the size in bytes of the stream needed to save the object
- //-----------------------------------------------------------------------------
- HRESULT $$CLASS_NAME$$::GetSizeMax(ULARGE_INTEGER *pcbSize)
- {
- if ( NULL == pcbSize )
- return E_POINTER;
-
- // Total size = size of(parameters) + sizeof(RIFF form type chunk) + sizeof(size chunk)
- pcbSize->QuadPart = sizeof($$TOOLID_NAME$$Params) + 2 * sizeof(DWORD);
- return S_OK;
- }
- $$ENDIF // END (SUPPORT_DM_IMEDPARAM || SUPPORT_DM_DMP)
-
- $$IF(SUPPORT_DM_DMP)
- //-----------------------------------------------------------------------------
- // Name: $$CLASS_NAME$$::GetPages()
- // Desc: Get the property pages GUIDs
- //-----------------------------------------------------------------------------
- HRESULT $$CLASS_NAME$$::GetPages(CAUUID *pPages)
- {
- // Only one property page is required for DMTool
- pPages->cElems = 1;
- pPages->pElems = static_cast<GUID *>(CoTaskMemAlloc(sizeof(GUID)));
-
- // Make sure memory is allocated for pPages->pElems
- if( pPages->pElems == NULL )
- {
- return E_OUTOFMEMORY;
- }
-
- // Return the propery page's class ID
- *(pPages->pElems) = CLSID_$$TOOL_DEFINE$$PROP;
- return S_OK;
- }
-
- $$ENDIF // END SUPPORT_DM_DMP
-
-